/**
 * Created Date: Monday, November 7th 2022, 11:39:05 pm
 * Author: CodingGorit
 * -----
 * Last Modified: Wed Feb 08 2023
 * Modified By: CodingGorit
 * -----
 * Copyright (c) 2022 fmin-courses
 * ------------------------------------
 * Javascript will save your soul!
 */


"use strict";
const nodemailer = require("nodemailer");

// async..await is not allowed in global scope, must use a wrapper
async function main() {
    // Generate test SMTP service account from ethereal.email
    // Only needed if you don't have a real mail account for testing
    let testAccount = await nodemailer.createTestAccount();

    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
        host: "smtp.qq.com",
        port: 465,
        secure: true,
        auth: {
            user: "你的qq邮箱",
            pass: "你的授权码"
        },
    });

    let testTramsporter = nodemailer.createTransport(testAccount);

    // send mail with defined transport object
    let info = await testTramsporter.sendMail({
        from: '"Fred Foo 👻"', // sender address
        to: ["你的邮箱地址"], // list of receivers
        subject: "Hello ✔", // Subject line
        text: "Hello world?", // plain text body
        html: "<b>Hello world?</b>", // html body
    });

    console.log("Message sent: %s", info.messageId);
    // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

    // Preview only available when sending through an Ethereal account
    console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
    // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}

// use ts-node to run it
main().catch(console.error);
